//向文件中写入数据
import java.io.*;
public class demo2 {
    public static void main(String[] args) throws Exception {
        File file = new File("D:" + File.separator + "java" + File.separator + "vip" + File.separator + "yootk.txt");

        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        OutputStream output = new FileOutputStream(file);
        String str = "www.yootk.com";
        byte[] data = str.getBytes();
        output.write(data);
        output.close();
//读取文件
        if (file.exists()) {
            try (InputStream input = new FileInputStream(file)) {

            byte data1[] = new byte[1024];
            int len = input.read(data1);
            System.out.println(new String(data1, 0, len));
        }
    }
        //使用writer读取文件
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        try (Writer out = new FileWriter(file)) {
            out.write("沐言科技：www.yootk.com");
            out.append("李兴华高新就业编程训练营：edu.yootk.com");
        } catch (Exception e) {

        }
        //使用reader读取文件
        if (file.exists()) {
            try (Reader in = new FileReader(file)) {
                char data2[] = new char[1024];
                int len = in.read(data2);
                System.out.println(new String(data2, 0, len));
            } catch (Exception e) {
            }
        }
    }
}
